import { constantRoutes, asyncRoutes } from '@/router'

const state = {
  router: constantRoutes || []
}
const mutations = {
  // otherRoutes 登录成功后，需要添加的新路由（根据用户权限筛选出来的动态路由）
  setRoutes(state, otherRoutes) {
    state.router = [...constantRoutes, ...otherRoutes]
  }
}
const actions = {
  // menus,根据接口返回的用户具备的权限点
  filterRoutes(context, menus) {
    console.log(asyncRoutes)
    console.log(menus)
    const otherRoutes = asyncRoutes.filter((item) =>
      menus.includes(item.children[0].name)
    )
    context.commit('setRoutes', otherRoutes)
    return otherRoutes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
